package com.yumeng.framework.persistence.mybatis.injector.methods;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 查找1个
 * 测试用
 * @author wxd
 * @date 2021/9/22 16:50
 */
public class FindOne extends AbstractMethod {

    public FindOne() {
        super("findOne");
    }

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        //findOne 仅支持演示表操作
/*        if (!tableInfo.getTableName().startsWith("demo_")){
            return null;
        }*/

        if (tableInfo.getTableName().contains("order")){
            return null;
        }

        String sql = "select * from " + tableInfo.getTableName()
                + " where " + tableInfo.getKeyColumn() + "=#{" + tableInfo.getKeyProperty() + "}";
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, Object.class);//非动态情况：Object.class 解析为 Object.class，modelClass解析为对应的#{}字段类型
        return addSelectMappedStatementForTable(mapperClass, sqlSource, tableInfo);

    }
}
